package com.ruoyi.platform.utils;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;


public class HttpUtil {

    /**
     * 获取当前请求的request对象
     * @return
     */
    public static HttpServletRequest getRequest() {
        RequestAttributes requestAttributes = null;
        try{
            requestAttributes = RequestContextHolder.currentRequestAttributes();
        }catch (IllegalStateException e){
            return null;
        }
        return ((ServletRequestAttributes) requestAttributes).getRequest();
    }
}
